package com.atguigu.servlet;

import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.*;

import java.io.IOException;

//12.演示request属性域 - 一次请求响应范围有效
//14.演示session属性域 - 一次会话范围有效
//16.演示application属性域 - 一次应用程序级别有效(tomcat启动开始一直到tomcat停止）
@WebServlet("/h12")
public class H12Servlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //向request属性域保存数据
        request.setAttribute("Hello","World");

        //向session属性域保存数据
        HttpSession session = request.getSession();
        session.setAttribute("country","China");

        //向application属性域保存数据
        //request.getServletContext()
        ServletContext application = session.getServletContext();
        application.setAttribute("country","中国");

        //服务器转发
        //request.getRequestDispatcher("h13").forward(request,response);

        //客户端重定向
        response.sendRedirect("h13");
    }
}
